<template>
  <div id="app">
    <router-view v-wechat-title="wechatTitle" />
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  metaInfo() {
    return {
      title: this.title,
      meta: [
        { name: 'description', content: this.siteInfo.seo_description },
        { name: 'keywords', content: this.siteInfo.seo_keyword }
      ],
      // 主题色
      link: [
        { rel: 'icon', href: this.siteInfo.ico_url },
        {
          rel: 'stylesheet',
          href: `/static/theme/${this.globTheme}/index.css`
        }
      ],
      script: [
        {
          type: 'text/javascript',
          src: `/static/theme/${this.globTheme}/index.css`
        }
      ]
    }
  },
  computed: {
    ...mapGetters({
      globTheme: 'projectSetting/getGlobTheme',
      globTitle: 'projectSetting/getGlobTitle',
      siteInfo: 'projectSetting/getGlobSiteInfo'
    }),
    wechatTitle() {
      const mateTitle = this.$route.meta.title
      const appTitle = this.globTitle
      return mateTitle ? `${appTitle} - ${mateTitle}` : appTitle
    }
  },
  beforeCreate() {
    this.$api.configSdn(res => {
      const { data } = res
      // 机构id
      this.$store.commit('projectSetting/setGlobSchoolId', data.mhm_id)
      // 初始化
      this.$store.dispatch('projectSetting/setConfig')
      // 设置菜单
      this.$store.dispatch('projectSetting/setMenus')
      // 全局开关
      this.$store.dispatch('projectSetting/setGlobSwitch')
      // 第三方登录
      this.$store.dispatch('projectSetting/setGlobThirdLoginConfig')
      // 登录
      if (this.$store.getters['user/isLogin']) {
        // 更新用户信息
        this.$store.dispatch('user/userInfo')
        this.$store.dispatch('user/userTicket')
        this.$store.dispatch('projectSetting/setGlobCartNumber')
        this.$store.dispatch('projectSetting/setGlobNotifyUnread')
      }
    })
  }
}
</script>
